<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数求阶乘</title>
</head>
<body>
    <script>
        //求阶乘
        function getJC(n){
            var num = 1;
            for(var i = 2; i<=n; i++){
                num *=i;
            }
            //返回阶乘
            return num;
        }
        console.log('3的阶乘是'+ getJC(3));//求3的阶乘
        //求1！+ 2！ + 3！+ ...+ n!(1~n!的阶乘的累加和)
        function getSum(n){
            var sum = 0;
            for(var i =1;i <=n;i++){
                //求每一个数阶乘的和
                sum += getJC(i);
            }
            return sum;
        }
        console.log('3的阶乘累加和是' +getSum(3)); //sum = 0+getSum(1) +getSum(2)+getSum(3)
        

    </script>
</body>
</html>